using System;
using System.Collections.Generic;
using Tao.OpenGl;

namespace WindowsApplication1
{
	static class Program
	{
		static bool quit = false;

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Gtk.Application.Init();

			Gtk.Window wnd = new Gtk.Window("Test");
			Gtk.VBox vbox = new Gtk.VBox();
			wnd.Add(vbox);

			Gtk.HPaned paned = new Gtk.HPaned();
			vbox.PackStart(paned,true,true,0);
			
			Dida.ManagedGlArea glarea = new Dida.ManagedGlArea();
			paned.Pack1(glarea, true, true);

			// create the size bar
			Gtk.Widget sidebar = CreateSideBar();
			paned.Pack2(sidebar, false, true);

			Gtk.Statusbar statusbar = new Gtk.Statusbar();
			statusbar.Push(0, "Rendering using OpenGl because it's just so fucking awesome!");
			vbox.PackStart(statusbar,false,true,0);

			wnd.Destroyed += 
				delegate(object sender,EventArgs args)
				{
					quit = true;
				};
			wnd.ShowAll();

			while (!quit)
			{
				while (Gtk.Application.EventsPending())
				{
					Gtk.Application.RunIteration();
				}

				glarea.BeginGl();
				Gl.glClearColor(.5f, .5f, .5f, 1);
				Gl.glClearDepth(1);
				Gl.glClearStencil(0);
				Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_STENCIL_BUFFER_BIT);
				glarea.EndGl();
				
			}
		}

		private static Gtk.Widget CreateSideBar()
		{
			Gtk.Notebook tabs = new Gtk.Notebook();
			tabs.TabPos = Gtk.PositionType.Right;
			
			Gtk.VBox vbox = new Gtk.VBox();
			vbox.BorderWidth = 6;
			vbox.Spacing = 6;
			tabs.AppendPage(vbox, new Gtk.Label("World"));

			Gtk.TreeView tree = new Gtk.TreeView();
			Gtk.ScrolledWindow scroller = new Gtk.ScrolledWindow();
			scroller.Add(tree);
			vbox.PackStart(scroller, true, true, 0);

			tabs.AppendPage(new Gtk.Button(), new Gtk.Label("Toolbox"));
			tabs.AppendPage(new Gtk.Button(), new Gtk.Label("Toolbox 2"));

			return tabs;
		}
	}
}